package com.app.service.impl;

import com.app.mapper.ActivityMapper;
import com.app.mapper.BusinessActivityMapper;
import com.app.model.ActivityModel;
import com.app.model.BusinessActivityModel;
import com.app.service.BusinessActivityService;
import com.app.vo.ActivityVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商家活动关联
 * @author 16693103420
 * @since 2024-01-22
 */
@Service
public class BusinessActivityServiceImpl extends ServiceImpl<BusinessActivityMapper, BusinessActivityModel> implements BusinessActivityService {
    @Autowired
    private ActivityMapper activityMapper;

    @Autowired
    private BusinessActivityMapper businessActivityMapper;
    //查询此商家活动
    @Override
    public ActivityVo getBusinessActivity(Integer businessId,Integer classification) {
        List<ActivityModel> businessActivityList = activityMapper.getBusinessActivityByIdAndClassification(businessId,classification);
        for (ActivityModel model : businessActivityList) {
            if (model.getIsPick()==1){
                model.setPick("是");
            }else {
                model.setPick("否");
            }
        }
        QueryWrapper<BusinessActivityModel> qw =new QueryWrapper<>();
        qw.eq("business_id", businessId);
        qw.orderByDesc("create_time");
        Integer count = businessActivityMapper.selectCount(qw);
        ActivityVo businessActivityVo =new ActivityVo();
        businessActivityVo.setList(businessActivityList);
        businessActivityVo.setCount(count);
        return businessActivityVo;
    }
}
